package com.smartStatus.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smartStatus.admin.service.CommonParametersService;
import com.smartStatus.api.entity.CommonParameters;
import com.smartStatus.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 公共参数 Controller
 *
 * @author lby
 * @since 2021-01-19
 */
@RestController
@Slf4j
@Api(value = "CommonParameters", tags = "公共参数管理")
@AllArgsConstructor
@RequestMapping("commonParameters")
public class CommonParametersController {

    private final CommonParametersService commonParametersService;

    /**
     * 分页数据
     */
    @PreAuthorize("@pms.hasPermission('sys_commonParmeters_view')")
    @ApiOperation(value = "公共参数分页数据")
    @GetMapping("/page")
    public R commonParametersPage(Page<CommonParameters> page, CommonParameters commonParameters) {
        QueryWrapper<CommonParameters> query = Wrappers.query();
        return R.ok(commonParametersService.page(page, query));
    }


    /**
     * 列表数据
     */
    @PreAuthorize("@pms.hasPermission('sys_commonParmeters_view')")
    @ApiOperation(value = "公共参数列表")
    @GetMapping("/list")
    public R commonParametersList() {
        return R.ok(commonParametersService.list());
    }


    /**
     * 编辑数据
     */
    @PreAuthorize("@pms.hasPermission('sys_commonParmeters_view')")
    @ApiOperation(value = "编辑公共参数")
    @ApiImplicitParam(name = "CommonParameters", value = "CommonParameters实体", required = true, dataType = "CommonParameters")
    @PutMapping("/edit")
    public R commonParametersUpdate(@RequestBody CommonParameters commonParameters) {
        return R.ok(commonParametersService.updateById(commonParameters));
    }


    /**
     * 删除数据
     */
    @PreAuthorize("@pms.hasPermission('sys_commonParmeters_view')")
    @ApiOperation(value = "删除公共参数")
    @ApiImplicitParam(name = "id", value = "common_parametersid", required = true, dataType = "Integer")
    @DeleteMapping("/{id}")
    public R commonParametersDelete(@PathVariable Integer id) {
        return R.ok(commonParametersService.removeById(id));
    }

    /**
     * 添加数据
     */
    @PreAuthorize("@pms.hasPermission('sys_commonParmeters_view')")
    @ApiOperation(value = "添加公共参数")
    @ApiImplicitParam(name = "CommonParameters", value = "CommonParameters实体", required = true, dataType = "CommonParameters")
    @PostMapping("/add")
    public R commonParametersInsert(@RequestBody CommonParameters commonParameters) {
        return R.ok(commonParametersService.save(commonParameters));
    }

}
